package com.haoxiaozhang.hxz_app;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.haoxiaozhang.hxz_app.activity.BaseActivity;
import com.haoxiaozhang.hxz_app.bean.User;
import com.haoxiaozhang.hxz_app.fragment.AnalyseFragment;
import com.haoxiaozhang.hxz_app.fragment.CenterFragment;
import com.haoxiaozhang.hxz_app.fragment.HomeFragment;
import com.haoxiaozhang.hxz_app.fragment.PendingFragment;
import com.haoxiaozhang.hxz_app.utils.T;

import androidx.fragment.app.FragmentTransaction;

public class IndexActivity extends BaseActivity {

    private HomeFragment homeFragment;
    private AnalyseFragment analyseFragment;
    private PendingFragment pendingFragment;
    private CenterFragment centerFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_index);

        //设置自定义toolbar
        setUpToolbar();

        //初始化fragment
        initFragment();


    }

    //初始化fragment
    private void initFragment() {

        //创建4个fragment
        homeFragment = new HomeFragment();
        analyseFragment = new AnalyseFragment();
        pendingFragment = new PendingFragment();
        centerFragment = new CenterFragment();

        //设置首页为首先展示的fragment
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.index_container,homeFragment);
        transaction.commit();

    }


    //tab点击事件处理
    public void tab_click(View view) {
        FragmentTransaction tabChangeTransaction = getSupportFragmentManager().beginTransaction();
        switch (view.getId()){
            case R.id.button_home:
                tabChangeTransaction.replace(R.id.index_container,homeFragment);
                break;
            case R.id.button_analyse:
                tabChangeTransaction.replace(R.id.index_container,analyseFragment);
                break;
            case R.id.button_pending:
                tabChangeTransaction.replace(R.id.index_container,pendingFragment);
                break;
            case R.id.button_center:
                tabChangeTransaction.replace(R.id.index_container,centerFragment);
                break;
        }
        tabChangeTransaction.commit();
    }
}
